const { ErrorModel } = require('../model/resModel');
const { exec,escape } = require('../db/mysql');

module.exports = (req, res, next) => {
  const { username } = req.body;
  console.log('username', username);
  const sql = `
        select username from users where username='${username}'
    `;
  exec(sql).then(rows => {
    if (rows[0]) {
      res.json(new ErrorModel(`用户名：${username}已经注册，请修改用户名`));
      return ;
    }
    next();
  }).catch(err => {
    console.log('req,注册验证', req);
    console.log('注册验证出错', err);
  })
};
